package db.exchange.message;

public class Message {

	private Order order;
	private MessageType type;
	private double lastPrice;
	private int lastQty;
	private String text;

//	public Message(Order order) {
//		this.order = order;
//	}
	
	public Message(Order order, MessageType type) {
		this.order = order;
		this.type = type;
	}
	
	public MessageType 	getType() 		{return type;}
	public double 		getLastPrice() 	{return lastPrice;}
	public int 			getLastQty() 	{return lastQty;}
	public String 		getText() 		{return text;}
	public MessageType 	getMessageType(){return type;}
	public String 		getClientId() 	{return order.getClientId();}	
	public String 		getOrderId() 	{return order.getOrderId();}

	public void setType(MessageType type) {this.type = type;}
	public void setLastPrice(double lastPrice) {this.lastPrice = lastPrice;}
	public void setLastQty(int lastQty) {this.lastQty = lastQty;}
	public void setText(String text) {this.text = text;}

	@Override
	public String toString() {
		StringBuilder row = new StringBuilder("35=8");
		row.append("|11=" + order.getOrderId());
		if (type == MessageType.ACK) {
			row.append("|39=0");
			return row.toString();
		}
		row.append("|38=" + order.getQty());
		row.append("|14=" + order.getCumQty());
		row.append("|151=" + order.getLeavesQty());
		row.append("|31=" + lastPrice);
		row.append("|32=" + lastQty);
		row.append(type.getFixSuffix());
		if (text != null)
			row.append("|44=" + text);
		return row.toString();
	}


	
}
